package com.zjw.demo.utils;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author:zhaojiawei
 * @Date: 2023/3/24 9:06
 */
@Slf4j
public class TimeUtils {

    public static void main(String[] args) {
        String time = time2String(LocalDateTime.now());
    }

    /**
     * 将时间转化为字符串
     * @param time 时间
     * @return
     */
    public static String time2String(LocalDateTime time){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return df.format(time);
    }

    /**
     * 将字符串转化为时间格式
     * @param timeStr 时间类型字符串
     * @return
     */
    public static LocalDateTime string2Time(String timeStr){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time = LocalDateTime.parse(timeStr, df);
        return time;
    }


}
